;(function($){
	$.fn.timesRoom_right = function(opts){
		var el = this;
		var opt = {
            id : "",
            entityBack : function(){},
			dataBack : function(){},
			closeBack : function(){},
		}
		var param = $.extend(opt,opts);
		var app = new App(el,param);
	}
	
	var App = function(el,param){
		this.el = el;
		this.param = param;
        this.initHtml();
        this.bindEvent();
        param.entityBack(this);
	}
	
	App.prototype={
		bindEvent : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			$(".room-item").contextMenu('operationMenu',{
				bindings:{
					//预定
					'roomRsv': function(tt){
                        var room = $(tt).data("room");
                        var ds = $.parseJSON($(tt).find(".json").html());
                        t.operRoom("预定",ds,tt);
					},
				},
				onContextMenu:function(e){
					var _this
					if(e.target.tagName=="DIV"){
						_this = $(e.target)
					}else{
						_this = $(e.target).parent("div")
					}
		        	return true;
				},
				onShowMenu: function(e, menu) {
					var _this
					if(e.target.tagName=="DIV"){
						_this = $(e.target)
					}else{
						_this = $(e.target).parent("div")
					}
			        return menu;
		      	}
			});
		},
		initHtml : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			var html =	'<style>'+
							'.submenu{position: relative;}'+
							'.submenu ul{left: 153px;top: -7px;display : none;}'+
							'.submenu .menu-forward i{position: absolute;right: 5px;font-size: 16px;}'+
							'.submenu:hover ul{display : block;}'+
						'</style>'+
						'<div class="contextMenu" id="operationMenu" style="display: none;">'+ 
						    '<ul class="dropdown-preview dropdown-menu dropdown-info">'+
						        '<li id="roomRsv">'+
						        	'<a href="JavaScript:void(0)" data-i18n="订房">'+
						        		$.i18n.propJsp("订房")+
						       		'</a>'+
						    	'</li>'+ 
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="开房">'+
						        		$.i18n.propJsp("开房")+
						       		'</a>'+
						    	'</li>'+ 
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="修改">'+
						        		$.i18n.propJsp("修改")+
						       		'</a>'+
						    	'</li>'+
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="退房">'+
						        		$.i18n.propJsp("退房")+
						       		'</a>'+
						    	'</li>'+
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="结账">'+
						        		$.i18n.propJsp("结账")+
						       		'</a>'+
						    	'</li>'+
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="换房">'+
						        		$.i18n.propJsp("换房")+
						       		'</a>'+
						    	'</li>'+   
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="脏净房">'+
						        		$.i18n.propJsp("脏净房")+
						       		'</a>'+
						    	'</li>'+  
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="房备注">'+
						        		$.i18n.propJsp("房备注")+
						       		'</a>'+
						    	'</li>'+     
						        '<li class="divider"></li>'+
						        '<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="商品开单">'+
						        		$.i18n.propJsp("商品开单")+
						       		'</a>'+
						    	'</li>'+ 
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="技师派遣">'+
						        		$.i18n.propJsp("技师派遣")+
						       		'</a>'+
						    	'</li>'+
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="在岗技师">'+
						        		$.i18n.propJsp("在岗技师")+
						       		'</a>'+
						    	'</li>'+
						    	'<li class="divider"></li>'+
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="派房">'+
						        		$.i18n.propJsp("派房")+
						       		'</a>'+
						    	'</li>'+
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="反派房">'+
						        		$.i18n.propJsp("反派房")+
						       		'</a>'+
						    	'</li>'+
						    	'<li class="divider"></li>'+
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="叫醒">'+
						        		$.i18n.propJsp("叫醒")+
						       		'</a>'+
						    	'</li>'+
						    	'<li class="divider"></li>'+
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="过夜房">'+
						        		$.i18n.propJsp("过夜房")+
						       		'</a>'+
						    	'</li>'+
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="反过夜房">'+
						        		$.i18n.propJsp("反过夜房")+
						       		'</a>'+
						    	'</li>'+
						    	'<li class="divider"></li>'+
						    	'<li id="" class="submenu">'+
						        	'<a class="menu-forward" href="JavaScript:void(0)" data-i18n="计时房">'+
						        		$.i18n.propJsp("计时房")+
						        		'<i class="ace-icon fa fa-angle-right"></i>'+
						       		'</a>'+
						       		'<ul class="dropdown-menu dropdown-info">'+//dropdown-preview 
						       			'<li id="">'+
								        	'<a href="JavaScript:void(0)" data-i18n="计时">'+
								        		$.i18n.propJsp("计时")+
								       		'</a>'+
								    	'</li>'+ 
								    	'<li id="">'+   
								        	'<a href="JavaScript:void(0)" data-i18n="换房">'+
								        		$.i18n.propJsp("换房")+
								       		'</a>'+
								    	'</li>'+ 
						       		'</ul>'+
						    	'</li>'+
						    	'<li class="divider"></li>'+
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="维修房">'+
						        		$.i18n.propJsp("维修房")+
						       		'</a>'+
						    	'</li>'+
						    	'<li id="">'+
						        	'<a href="JavaScript:void(0)" data-i18n="制房卡">'+
						        		$.i18n.propJsp("制房卡")+
						       		'</a>'+
						    	'</li>'+
						    '</ul>'+ 
						    ''+
						'</div>';			
			$("#main-container").find("#operationMenu").remove();
			$("#main-container").append(html);
        },
        operRoom : function(oper,ds,tt){
            var el = this.el;
            var param = this.param;
            var t = this;
            
            $(tt).modalFrame("destroy");
			$(tt).modalFrame("init",function(modalEle){  
				$("#"+modalEle).modal("show");
				$("#"+modalEle).show();
		    	if(!$.isFunction($().timesRoom_oper)){
					$.ajaxSetup({ async: false, cache: false });
		            $.getScript("js/timesRoom/jquery.modal.timesRoom_oper.js");
		            $.ajaxSetup({ async: true });
				}
				$("#"+modalEle).timesRoom_oper({
					title : "预定",
					room : ds.room,
					dataBack:function(data){
						
					},
					closeBack:function(data){
						
					}
				});
			})
        },
	}
})(jQuery);